package com.serverImpl;

import java.util.List;
import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.beans.Article;
import com.mapper.ArticleMapper;
import com.server.ArticleService;

@Service
@Transactional
public class ArticleServiceImpl implements ArticleService{
    @Autowired
    private ArticleMapper articleMapper;

    public Article searchByArticleID(Integer articleID){
        return articleMapper.searchByArticleID(articleID);
    }

    public List<Article> getAllArticles() {
        return articleMapper.getAllArticles();
    }

    public Article getArticleById(Long articleID) {
        return articleMapper.getArticleById(articleID);
    }

    public List<Article> getArticlesByGradeId(Long gradeId) {
        return articleMapper.getArticlesByGradeId(gradeId);
    }

    public List<Article> searchArticles(String keyword) {
        return articleMapper.searchArticles(keyword);
    }

    public int addArticle(Article article) {
        return articleMapper.insertSelective(article);
    }

    public Article getArticle(Integer articleID) {
        return articleMapper.searchByArticleID(articleID);
    }

    public void deleteArticle(Integer articleID) {
        articleMapper.delByArticleID(articleID);
    }

    public void updateArticle(Article article) {
        articleMapper.updateSelective(article);
    }

    @Override
    public List<Article> selectArticlesByGrade(String grade) {
        return articleMapper.selectArticlesByGrade(grade);
    }
}
